package TCP;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    public static void main(String args[]) throws IOException {

        //new 对象
//        192.168.0.187
        Socket socket=new Socket("192.168.162.60",8888);

        //在通信管道上得到字节输出流
        OutputStream os=socket.getOutputStream();

        //把低级输出流包装成数据输出流
        DataOutputStream dos=new DataOutputStream(os);

        Scanner sc=new Scanner(System.in);
        while(true){
            System.out.println("请说：");
            String msg=sc.nextLine();
            if(msg.equals("exit")){
                System.out.println("退出成功");
                dos.close();
                socket.close();
            }
            //写入数据
            dos.writeUTF(msg);
            dos.flush();
        }


    }
}
